#ifndef DBAPP_H
#define DBAPP_H

#pragma once

#include <QSqlDatabase>
#include "dbtype.h"

class QSqlQuery;

namespace ns_yht
{

#define DBAPP DbApp::instance()
#define DATABASE (DBAPP->getDbApp())

    class DbApp
    {
    public:
        DbApp();
        DbApp(const QString &host, const QString &database, const QString &uid, const QString &pwd);
        ~DbApp();

        static DbApp *instance();

        QSqlDatabase &getDbApp();
        bool isOk() const;

        DBType getDbType() const;

        void reloadDB();
        void showErrorInfo(const QString &module, const QSqlQuery &query);

    private:
        QSqlDatabase m_dbApp;

        DBType m_dbType;

        static DbApp *g_dbApp;
    };

} // namespace ns_yht
#endif // DBAPP_H
